﻿using System;
using spaar.ModLoader;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Events;
using System.Collections.Generic;
using ShooterGameMOD_Besiege.Player;
using PluginManager.Plugin;


namespace ShooterGameMOD_Besiege
{

    // If you need documentation about any of these values or the mod loader
    // in general, take a look at https://spaar.github.io/besiege-modloader.

    public class ShooterGameMod : Mod
    {
        public override string Name { get; } = "<placeholder>";
        public override string DisplayName { get; } = "<placeholder>";
        public override string Author { get; } = "<placeholder>";
        public override Version Version { get; } = new Version(1, 0, 0);

        // You don't need to override this, if you leavie it out it will default
        // to an empty string.
        public override string VersionExtra { get; } = "";

        // You don't need to override this, if you leave it out it will default
        // to the current version.
        public override string BesiegeVersion { get; } = "v0.45a";

        // You don't need to override this, if you leave it out it will default
        // to false.
        public override bool CanBeUnloaded { get; } = false;

        // You don't need to override this, if you leave it out it will default
        // to false.
        public override bool Preload { get; } = false;


        GameObject ShooterGame = new GameObject("Shooter Game");

        public override void OnLoad()
        {
            // Your initialization code here        

            //UnityEngine.Object.DontDestroyOnLoad(PlayerScript.Instance);

            ShooterGame.AddComponent<WeaponScript>();
            ShooterGame.AddComponent<PlayerScript>();

            UnityEngine.Object.DontDestroyOnLoad(ShooterGame);

            SceneManager.sceneLoaded += OnSceneLoaded;

        }

        public override void OnUnload()
        {
            // Your code here
            // e.g. save configuration, destroy your objects if CanBeUnloaded is true etc
        }

        static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
        {
            Debug.Log("loaded scene" + scene.name);
            PlayerScript.playerCreated = false;

        }

        static public bool isBuilding()
        {

            List<string> scene = new List<string> { "TITLE SCREEN", "LevelSelect", "LevelSelect1", "LevelSelect2", "LevelSelect3" };


            if (SceneManager.GetActiveScene().isLoaded)
            {

                if (!scene.Exists(match => match == SceneManager.GetActiveScene().name))
                {
                    return true;
                }
            }

            return false;

        }
    }
}


